package edu.spbu.eclipse.adressbook.zhukovazalog;
/** @author Anna Zhukova
 * @author Leonid Zalog
 *
 */
import java.util.*;

public class XMLBuilder {
	private int Statement = 1;

	private int flagStmnt = 1;

	private Vector row = new Vector();

	private LinkedList l = new LinkedList();

	private String name1 = new String();

	public void setStatement(int newStatement) {
		this.Statement = newStatement;
	}

	public int getStatement() {
		return this.Statement;
	}

	public void endOfFile() {
		row.add(l);
		l = new LinkedList();
		Surface.data.add(row);
		row = new Vector();
		flagStmnt = 1;
	}

	public void TagOpened(String name) {
		if (name.equalsIgnoreCase("<name>")) {
			this.setStatement(1);
		} else if (name.equalsIgnoreCase("<lastName>")) {
			this.setStatement(2);
		} else if (name.equalsIgnoreCase("<mobileNumber>")) {
			this.setStatement(3);
		} else if (name.equalsIgnoreCase("<homeNumber>")) {
			this.setStatement(4);
		} else if (name.equalsIgnoreCase("<email>")) {
			this.setStatement(5);
		}
	}

	public void Text(String name, int statement) {
		name1 = name;
	}

	public void TagClosed(String name) {
		if (flagStmnt != Statement) {
			flagStmnt = Statement;
			row.add(l);
			if (Statement == 1) {
				Surface.data.add(row);
				row = new Vector();
			}
			l = new LinkedList();
		}
		l.add(name1);
		name1 = "";
	}

}
